﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TvdP
{
    public static partial class Adapters
    {
        class TargetedAdapter<ToType> : IAdapters<ToType>
            where ToType : class
        {
            public IAdapters _untypedAdapter;

            public ToType Cast(object adaptee)
            { return _untypedAdapter.Cast<ToType>(adaptee); }

            public object GetBase(ToType solution)
            { return _untypedAdapter.GetBase(solution); }

            public bool CanCast(Type fromType)
            { return _untypedAdapter.CanCast(fromType, typeof(ToType)); }
        }

        public static IAdapters<TTo> GetTargetedAdapter<TTo>(this IAdapters adapter)
            where TTo : class
        {
            CheckAdapter(adapter);

            return new TargetedAdapter<TTo>() { _untypedAdapter = adapter };
        }

    }
}
